package com.lyb.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.service.BrandService;
import com.lyb.spzx.model.entity.product.Brand;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌管理接口")
@RestController
@RequestMapping("admin/product/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @Operation(summary = "分页查询品牌")
        @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<Brand>> findBrandByPage(@PathVariable(value = "pageNum") Integer pageNum,
                                                         @PathVariable(value = "pageSize") Integer pageSize){
        PageInfo<Brand> pageInfo = brandService.findByPage(pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加品牌")
    @PostMapping("/save")
    public Result addBrand(@RequestBody Brand brand){
        brandService.addBrand(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改品牌")
    @PutMapping("/update")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.updateBrand(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/delete/{id}")
    public Result deleteBrandById(@PathVariable Integer id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有品牌")
    @GetMapping("/findAllBrand")
    public Result<Brand> findAllBrand(){
        List<Brand> brands = brandService.findAllBrand();
        return Result.build(brands,ResultCodeEnum.DATA_ERROR);
    }
}
